package com.dream.utils.check;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.dream.utils.date.DateParseUtils;

/**
 * 
 * @author Evan
 * @date 2013/8/25
 *
 */
public abstract class CommonCheck {
	private static Pattern MOBILE_PAT;
	private static Pattern PHONE_PAT;
	private static Pattern NUMBER_PAT;
	private static Pattern MAIL_PAT;
	private static Pattern NUM_OR＿CHAR;
	static {
		
		MOBILE_PAT = Pattern.compile(PatternExpConstants.MOBILE_PAT);
		PHONE_PAT = Pattern.compile(PatternExpConstants.PHONE_PAT);
		NUMBER_PAT = Pattern.compile(PatternExpConstants.NUM_PAT);
		MAIL_PAT = Pattern.compile(PatternExpConstants.MAIL_PAT);
		NUM_OR＿CHAR = Pattern.compile(PatternExpConstants.NUM_OR＿CHAR);
	}
	
	public static boolean isIllegalLen(String val,int len){
		 if(null == val)
			 return true;
		 return (val.length() != len);
	}
	public static boolean isIllegalMinLen(String val, int minLen){
		 if(null == val)
			 return true;
		 return (val.length() < minLen);
	}
	
	public static boolean isIllegalMaxLen(String val, int maxLen){
		 if(null == val)
			 return true;
		 return (val.length() > maxLen);
	}
	
	public static boolean isIllegalRangeLen(String val, int minLen,int maxLen){
		 if(null == val)
			 return true;
		 return (val.length() < minLen) || (val.length() > maxLen) ;
	}
	
	public static boolean isNotPhone(String phone){
		if(null == phone)
			 return true;
		Matcher matcher = PHONE_PAT.matcher(phone);
		return !matcher.find();
	}
	public static boolean isNotMoible(String phone){
		if(null == phone)
			 return true;
		Matcher matcher = MOBILE_PAT.matcher(phone);
		return !matcher.find();
	}
	public static boolean isNotNumric(String val){
		Matcher matcher = NUMBER_PAT.matcher(val);
		return !matcher.find();
	}
	public static boolean isNotNumOrChar(String val){
		Matcher matcher = NUM_OR＿CHAR.matcher(val);
		return !matcher.find();
	}
	
	public static boolean isNotDouble(String val){
		
		try{
			Double.parseDouble(val);
			return false;
		}catch(Exception e){
			return true;
		}
	}
	
	public static boolean isNotMail(String mail){
		if(null == mail)
			 return true;
		Matcher matcher = MAIL_PAT.matcher(mail);
		return !matcher.find();
	}
	
	public static boolean isNotDate(String strDate){
		Date date = DateParseUtils.parseDate(strDate,DateParseUtils.DEFAULT_DATE_FORMAT,"-");
		return date==null?true:false;
	}
	
	public static void main(String[] args){
		System.out.println(isNotPhone("12345678G"));
		System.out.println(isNotNumric("a"));
	}
}
